int calculate(char* s) {
    int n = strlen(s);
    int stk[n], top = 0;
    char preSign = '+';
    int num = 0;
    for (int k = 0; k < n; ++k) {
        if (isdigit(s[k])) {
            num = num * 10 + (int)(s[k] - '0');
        }
        if (!isdigit(s[k]) && s[k] != ' ' || k == n - 1) {
            switch (preSign) {
                case '+':
                    stk[top++] = num;
                    break;
                case '-':
                    stk[top++] = -num;
                    break;
                case '*':
                    stk[top - 1] *= num;
                    break;
                default:
                    stk[top - 1] /= num;
            }
            preSign = s[k];
            num = 0;
        }
    }
    int r = 0;
    for (int k = 0; k < top; k++) {
        r += stk[k];
    }
    return r;
}
